<template>
  <view class="page">
    <view v-for="(s, index) in stations" :key="s.id" class="station-item" @tap="choose(s)">
      <view class="left">
        <image class="pin" src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/dingwei.png" mode="widthFix"></image>
        <view class="info">
          <view class="name">{{ s.name }}</view>
          <view class="dist">{{ s.distanceText }}</view>
        </view>
      </view>

      <view class="right">
        <view class="btn ghost" @tap.stop="call(s.phone)">联系电话</view>
        <view class="btn primary" @tap.stop="nav(s)">导航</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      stations: []
    }
  },
  onLoad() {
    const channel = this.getOpenerEventChannel()
    channel.on('sendStations', (data) => {
      this.stations = data.stations || []
    })
  },
  methods: {
    choose(station) {
      uni.$emit('stationSelected', station)
      uni.navigateBack()
    },
    call(phone) {
      if (!phone) return uni.showToast({ title: '无联系电话', icon: 'none' })
      uni.makePhoneCall({ phoneNumber: phone })
    },
    nav(station) {
      if (!station.latitude || !station.longitude) {
        return uni.showToast({ title: '无坐标信息', icon: 'none' })
      }
      uni.openLocation({
        latitude: parseFloat(station.latitude),
        longitude: parseFloat(station.longitude),
        name: station.name,
        address: station.address || ''
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.page {
  background: #f2f3f5;
  min-height: 100vh;
  padding: 24rpx;
}
.title {
  font-size: 34rpx;
  color: #222;
  font-weight: 700;
  text-align: center;
  padding: 20rpx 0 40rpx;
}

/* 卡片样式 */
.station-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border-radius: 20rpx;
  padding: 24rpx 28rpx;
  margin-bottom: 24rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}

.left {
  display: flex;
  align-items: center;
}
.pin {
  width: 36rpx;
  height: 36rpx;
  margin-right: 16rpx;
}
.info {
  display: flex;
  flex-direction: column;
}
.name {
  font-size: 30rpx;
  color: #222;
  font-weight: 700;
}
.dist {
  background: #e9f4ff;
  color: #0a67b8;
  border-radius: 10rpx;
  font-size: 24rpx;
  padding: 4rpx 12rpx;
  display: inline-block;
  margin-top: 8rpx;
}

.right {
  display: flex;
  gap: 14rpx;
}
.btn {
  min-width: 130rpx;
  text-align: center;
  padding: 16rpx 0;
  border-radius: 12rpx;
  font-size: 26rpx;
}
.btn.ghost {
  background: #eef2f5;
  color: #3b3f45;
}
.btn.primary {
  background: #0a67b8;
  color: #fff;
}
</style>
